//
//  ReturnIntegralView.m
//  Logistics
//
//  Created by 刘峰 on 2018/4/23.
//  Copyright © 2018年 com.Logistics. All rights reserved.
//

#import "ReturnIntegralView.h"

@interface ReturnIntegralView ()

@property (nonatomic, strong) UIView *backgroundView;

@property (nonatomic, strong) UIView *integralView;

@property (nonatomic, strong) UILabel *integralLabel;

@end

@implementation ReturnIntegralView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self buildUI];
    }
    return self;
}

- (void)buildUI {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    _backgroundView  = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [window addSubview:_backgroundView];
    [window bringSubviewToFront:_backgroundView];
    
//    [_backgroundView addTapGesture:self sel:@selector(hideIntegral)];
    
    _integralView = [[UIView alloc] initWithFrame:CGRectMake((KscreenWidth-270)/2,-357 , 270, 357)];
    [_backgroundView addSubview:_integralView];
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _integralView.width, 303)];
    imageView.image = [UIImage imageNamed:@"goodDetail_10"];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    [_integralView addSubview:imageView];
    
    
    _integralLabel = [[UILabel alloc] init];
    _integralLabel.textColor = HEXCOLOR(0x0FFB241);
    _integralLabel.font = [UIFont boldSystemFontOfSize:35];
    [_integralView addSubview:_integralLabel];
    
    [_integralLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_integralView.mas_centerX);
        make.top.mas_equalTo(_integralView.mas_top).offset(172);
        make.height.mas_equalTo(@(34));
    }];
    UILabel * nameLabel = [[UILabel alloc] init];
    nameLabel.textColor = HEXCOLOR(0x0FFB241);
    nameLabel.font = [UIFont boldSystemFontOfSize:18];
    nameLabel.text = @"龟米";
    [_integralView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_integralLabel.mas_bottom);
        make.left.equalTo(_integralLabel.mas_right).offset(8);
        make.height.mas_equalTo(@18);
    }];
    UILabel *textLabel = [[UILabel alloc] init];
    textLabel.text = @"确认收货后，龟米将自动打\n入到您的账户上";
    textLabel.numberOfLines = 2;
    textLabel.textAlignment = NSTextAlignmentCenter;
    textLabel.font = [UIFont systemFontOfSize:12];
    textLabel.textColor = HEXCOLOR(0xDDDDDD);
    [_integralView addSubview:textLabel];
    
    [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_integralLabel.mas_centerX);
        make.top.mas_equalTo(_integralLabel.mas_bottom).offset(5);
        
        
    }];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setImage:[UIImage imageNamed:@"close_2"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(hideIntegral) forControlEvents:UIControlEventTouchUpInside];
    [_integralView addSubview:closeBtn];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_integralView.mas_centerX);
        make.bottom.mas_equalTo(_integralView.mas_bottom);
        make.height.mas_equalTo(@(30));
        make.width.mas_equalTo(@(30));
        
    }];
    

    _backgroundView.hidden = YES;
    _integralView.hidden   = YES;
}

- (void)setIntegral:(NSString *)integral {
    _integralLabel.text = integral;
}

- (void)showIntegral {
    _backgroundView.hidden = NO;
    _integralView.hidden   = NO;
    WEAKSELF
    [UIView animateWithDuration:.3 animations:^{
        weakSelf.backgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.5];
        weakSelf.integralView.centerY = self.backgroundView.centerY;
    }];
}

- (void)hideIntegral {
    WEAKSELF
    [UIView animateWithDuration:.3 animations:^{
        weakSelf.backgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
        weakSelf.integralView.y = -357;
    } completion:^(BOOL finished) {
        weakSelf.backgroundView.hidden = YES;
        weakSelf.integralView.hidden   = YES;
    }];
}


/*
 
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
